package com.ybfenpan.controller.member.shop;


import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.ybfenpan.controller.core.BaseController;
import com.ybfenpan.model.Member;
import com.ybfenpan.model.shop.Orders;
import com.ybfenpan.service.shop.OrdersService;
import com.ybfenpan.taglib.pagetag.Pagination;
import com.ybfenpan.utils.ContextUtil;
import com.ybfenpan.utils.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;







/**
 * Created by Administrator on 2016/3/25.
 */
@Controller

public class MyOrdersListController extends BaseController {
    @Resource
    private OrdersService ordersService;
   
   
    @RequestMapping("member/shop/ordersList.shtml")
    public String list(HttpServletRequest request) throws Exception{
        HashMap formMap = getParameterMap(request);
        
        
        Member member = ContextUtil.getMember();
        formMap.put("memberLoginName", member.getLoginName());	
        
        formMap.put("pagination.orderBy"," a.id desc");  //排列
        Pagination page = ordersService.queryForPageList("ordersForPage",formMap);
        request.setAttribute(Pagination.pageBeanName, page);
        return "member/shop/ordersList";
    }
    
    @RequestMapping("member/shop/ordersShow.shtml")
    public String use(HttpServletRequest request) throws Exception{
        Map formMap = getParameterMap(request);
        Member member = ContextUtil.getMember();
        int id = MapUtil.getIntValue(formMap, "id");
        if(0 < id){
        	Orders orders =ordersService.getByKey(id);
        	Map mapOrders = new HashMap();
        	mapOrders.put("id",id);
        	  
        	if(orders.getOrderState()==1&&orders.getMemberId().equals(member.getId())){
        		 
        		mapOrders.put("orderState",3);
        		mapOrders.put("shouDate",new Date());
        		 
        	} 
        	ordersService.update(mapOrders);
        }
        return "redirect:ordersList.shtml";
       
    }
    
}
